﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YJKRevitDimensionText.OneKeyPlanDim.Utility;

namespace YJKRevitDimensionText.OneKeyPlanDim
{
	public partial class OneKeyPlanDimForm : System.Windows.Forms.Form
	{
		public OneKeyPlanDimForm()
		{
			this.InitializeComponent();
			this.ReadDataFromFile();
		}

		private void WriteDataToFile()
		{
			FileStream fileStream = new FileStream(Path.GetTempPath() + this.m_strFileName, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.chkOutArchSize.Checked);
			streamWriter.WriteLine(this.chkOutArchLevel.Checked);
			streamWriter.WriteLine(this.chkOutArchSlope.Checked);
			streamWriter.WriteLine(this.chkInArchSize.Checked);
			streamWriter.WriteLine(this.chkInArchLevel.Checked);
			streamWriter.WriteLine(this.chkInArchSlope.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void ReadDataFromFile()
		{
			string path = Path.GetTempPath() + this.m_strFileName;
			if (!File.Exists(path))
			{
				this.chkInArchLevel.Checked = true;
				this.chkInArchSize.Checked = true;
				this.chkInArchSlope.Checked = true;
				this.chkOutArchLevel.Checked = true;
				this.chkOutArchSize.Checked = true;
				this.chkOutArchSlope.Checked = true;
				return;
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			this.m_bOutArchSize = Convert.ToBoolean(streamReader.ReadLine());
			this.m_bOutArchLevel = Convert.ToBoolean(streamReader.ReadLine());
			this.m_bOutArchSlope = Convert.ToBoolean(streamReader.ReadLine());
			this.m_bInArchSize = Convert.ToBoolean(streamReader.ReadLine());
			this.m_bInArchLevel = Convert.ToBoolean(streamReader.ReadLine());
			this.m_bInArchSlope = Convert.ToBoolean(streamReader.ReadLine());
			this.chkInArchLevel.Checked = this.m_bInArchLevel;
			this.chkInArchSize.Checked = this.m_bInArchSize;
			this.chkInArchSlope.Checked = this.m_bInArchSlope;
			this.chkOutArchLevel.Checked = this.m_bOutArchLevel;
			this.chkOutArchSize.Checked = this.m_bOutArchSize;
			this.chkOutArchSlope.Checked = this.m_bOutArchSlope;
			streamReader.Close();
			fileStream.Close();
		}

		private void btnStartDim_Click(object sender, EventArgs e)
		{
			this.WriteDataToFile();
			this.SetOneKeyPlanDimSelctionDim();
		}

		private void SetOneKeyPlanDimSelctionDim()
		{
			OneKeyPlanDimSelctionDim.m_bOutArchSize = this.chkOutArchSize.Checked;
			OneKeyPlanDimSelctionDim.m_bOutArchLevel = this.chkOutArchLevel.Checked;
			OneKeyPlanDimSelctionDim.m_bOutArchSlope = this.chkOutArchSlope.Checked;
			OneKeyPlanDimSelctionDim.m_bInArchSize = this.chkInArchSize.Checked;
			OneKeyPlanDimSelctionDim.m_bInArchLevel = this.chkInArchLevel.Checked;
			OneKeyPlanDimSelctionDim.m_bInArchSlope = this.chkInArchSlope.Checked;
		}

		private void OneKeyPlanDimForm_KeyDown(object sender, KeyEventArgs e)
		{
			try
			{
				Keys keyCode = e.KeyCode;
				if (keyCode == Keys.Escape)
				{
					base.Close();
				}
			}
			catch
			{
			}
		}

		private void OneKeyPlanDimForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		public bool m_bOutArchSize = true;

		public bool m_bOutArchLevel = true;

		public bool m_bOutArchSlope = true;

		public bool m_bInArchSize = true;

		public bool m_bInArchLevel = true;

		public bool m_bInArchSlope = true;

		private string m_strFileName = "OneKeyPlanDimForm.dat";
	}
}
